package sms;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/CheckSMSCodeServlet")
public class CheckSMSCodeServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.设置编码
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");

        //2.获取请求参数
        //获取用户输入的验证码
        String userCode=request.getParameter("code");

        //3.进行业务处理
        //从session获取发送的短信验证码
        String code= (String) request.getSession().getAttribute("code");

        //4.响应返回结果
        if(code.equalsIgnoreCase(userCode)){
            response.getWriter().print(true);
        }else{
            response.getWriter().print(false);
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
